<template>
  <section class="container">
    <!-- 头部面包屑导航 -->
    <div>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/post' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>攻略详情</el-breadcrumb-item>
      </el-breadcrumb>

      <div class="neirong">
        <div class="neirong_zuobian">
          <!-- 左边 -->
          <h2>{{p[0].title}}</h2>
          <div class="yuedu1">
            <p class="yuedu">攻略： {{p[0].updated_at|time}} 阅读：{{p[0].watch}}</p>
          </div>
          <div class="zhengwen">
            <p v-html="p[0].content" class="actical"></p>
          </div>
        </div>
        <!-- 右边 -->
        <div class="youbian">
          <h3>相关攻略</h3>
          <div class="youbian_xiahuax" v-for="(item,index) in chebian" :key="index">
            <span class="youbian_liebiao">
              <img :src="item.images[0]" alt />
              <span>
                <div>{{item.title}}</div>
                <p>{{item.updated_at|time}} 阅读{{item.watch}}</p>
              </span>
            </span>
          </div>
        </div>
      </div>

      <div class="dian">
        <div>
          <i class="iconfont iconpinglun"></i>
          <p>评论[{{p[0].comments.length}}]</p>
        </div>
        <div @click="shoucang">
          <i class="iconfont iconstar1"></i>
          <p>收藏</p>
        </div>
        <div>
          <i class="iconfont iconfenxiang"></i>
          <p>分享</p>
        </div>
        <div @click="dianzan">
          <i class="iconfont iconding"></i>
          <p v-if="p[0].like ==null">点赞( 0 )</p>
          <p v-else>点赞( {{p[0].like}} )</p>
        </div>
      </div>

      <!-- 评论区域 -->
      <pinlun :post="p" />
    </div>
  </section>
</template>

<script>
import moment from "moment";

import pinlun from "@/components/post/pinlun.vue";
export default {
  components: {
    pinlun
  },
  data() {
    return {
      p: [{ title: "", comments: [], account: {}, comments: {} }],
      chebian: []
    };
  },
  mounted() {
    const { id } = this.$route.query;
    this.$axios({
      url: "/posts",
      params: {
        id
      }
    }).then(res => {
      const { data } = res.data;

      this.p = data;
      // console.log("请求页面", this.p);
    });

    this.$axios({
      url: "/posts/recommend",
      params: {
        id
      }
    }).then(res => {
      console.log("推荐文章", res.data.data);
      this.chebian = res.data.data;
    });
  },
  methods: {
    // 点赞
    dianzan() {
      this.$axios({
        url: "/posts/like",
        params: {
          id: this.$route.query.id
        },
        headers: {
          Authorization: "Bearer " + this.$store.state.user.userInfo.token
        }
      }).then(res => {
        // console.log('点赞',res);
        this.p[0].like += 1;
      });
    },

    // 收藏
    shoucang() {
      this.$axios({
        url: "/posts/star",
        params: {
          id: this.$route.query.id
        },
        headers: {
          Authorization: "Bearer " + this.$store.state.user.userInfo.token
        }
      }).then(res => {
        // console.log(res);
        this.$message({
          showClose: true,
          message: res.data.message
        });
      });
    }
  },

  filters: {
    time(val) {
      return moment(val).format("YYYY-MM-DD hh:mm");
    }
  }
};
</script>
<style lang="less" scoped>
.container {
  width: 1000px;
  display: flex;
  justify-content: space-between;
  margin: 0 auto;
  margin-bottom: 20px;
}
.neirong {
  display: flex;
  justify-content: space-between;
  .neirong_zuobian {
    width: 700px;
    img {
      width: 700px;
      margin-top: 10px;
      margin-right: 20px;
    }
  }
  h2 {
    padding: 20px 0;
    border-bottom: 1px solid #ccc;
    margin-right: 20px;
  }
  .yuedu1 {
    height: 64px;
    .yuedu {
      float: right;
      font-size: 16px;
      color: #ccc;
      padding: 20px 0;
      margin-right: 20px;
    }
  }
  /deep/ .zhengwen {
    width: 660px;
    img {
      max-width: 660px;
    }
  }
  // /deep/p {
  //   /deep/img {
  //     width: 660px;
  //   }
  // }
  .shangwen {
    margin-top: 62px;
    margin-right: 18px;
  }

  // 右边
  .youbian {
    padding: 20px 0;
    width: 280px;
    .youbian_xiahuax {
      border-bottom: 1px solid #ccc;
    }
    float: right;
    h3 {
      font-weight: 200;
      border-bottom: 1px solid #ccc;
      margin-bottom: 20px;
    }
    .youbian_liebiao {
      display: flex;
      justify-content: space-between;
      margin: 20px 0;
      img {
        width: 100px;
        height: 80px;
      }
      span {
        div {
          font-size: 12px;
          padding: 8px 0;
        }
        p {
          // margin-top: 30px;
          font-size: 12px;
          color: #ccc;
        }
      }
    }
  }
}

.dian {
  display: flex;
  justify-content: space-between;
  justify-content: center;

  div {
    margin-left: 20px;
    i {
      display: flex;
      justify-content: center;
      font-size: 36px;
      color: skyblue;
      margin-top: 30px;
    }
  }
}
</style>